package sort;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: yi
 * Date: 2024-07-28
 * Time: 10:39
 */
public class ShellSort {
    public static void sort(int[] array){
        int gap = array.length;
        while(gap != 1){
            gap /= 2;
            shell(array,gap);
        }
        shell(array,gap);
    }
    private static void shell(int[] array,int gap){
        for (int i = gap; i < array.length; i++) {
            int tmp = array[i];
            int j = i - gap;
            for (; j >= 0; j -= gap) {
                if(tmp < array[j]){
                    array[j+gap] = array[j];
                }else{
                    break;
                }
            }
            array[j+gap] = tmp;
        }
    }
}
